﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CCWin;
namespace UI.UserInfo
{
    public partial class UserInfoDetail : Form
    {
        public UI.UserInfo.UserInfo parUserInfo;
        public Model.UserInfo uinfo;
        public DataTable JobDataTable;
        public UserInfoDetail()
        {
            InitializeComponent();
        }

        private void UserInfoDetail_Load(object sender, EventArgs e)
        {
            btn_uid.Text = Convert.ToString(uinfo.Uid);
            btn_name.Text = Convert.ToString(uinfo.Name);
            btn_birth.Text = Convert.ToString(uinfo.Birthday);
            btn_job.Text = Convert.ToString(uinfo.Jobid);
            btn_phone.Text = Convert.ToString(uinfo.Phone);
            textbox_qq.Text = Convert.ToString(uinfo.Qq);
            btn_address.Text = Convert.ToString(uinfo.Address);
            if (uinfo.Enable == 1)
            {
                comboxenable.SelectedIndex = 1;
            }
            else {
                comboxenable.SelectedIndex = 0;
            }
            this.Text = btn_name.Text + "+员工信息";
            if (uinfo.Sex == 0)
            {
                comboxsex.SelectedIndex = 0;
            }
            else {
                comboxsex.SelectedIndex = 1;
            }
            //
            if (uinfo.Enable == 0)
            {
                comboxenable.SelectedIndex = 0;
            }
            else
            {
                comboxenable.SelectedIndex = 1;
            }
         //   btn_job.Text = BLL.UserManager.SelectJobByUid(uinfo);
            ////-----------------
            JobDataTable = BLL.UserManager.departjob_3().Tables[0];
            for (int i = 0; i < JobDataTable.Rows.Count; i++)
            {
                btn_job.Items.Add(JobDataTable.Rows[i][2]);
                if (Convert.ToInt32(JobDataTable.Rows[i][0]) == uinfo.Jobid) btn_job.SelectedIndex = i;

            }
            
        }

        private void skinLabel9_Click(object sender, EventArgs e)
        {

        }

        private void btn_update_Click(object sender, EventArgs e)
        {
            Model.UserInfo uinfo = new Model.UserInfo();
            uinfo.Uid = Convert.ToInt32(btn_uid.Text);
            uinfo.Name=btn_name.Text;
            uinfo.Birthday = btn_birth.Text;
            uinfo.Phone=btn_phone.Text;
            uinfo.Qq=textbox_qq.Text;
            uinfo.Address=btn_address.Text;
            int CombSex = comboxsex.SelectedIndex;
            int combJob = btn_job.SelectedIndex;
            int jobid=Convert.ToInt32(JobDataTable.Rows[combJob][0]);
            uinfo.Sex = CombSex;
            uinfo.Jobid = jobid;
            int isEnable = comboxenable.SelectedIndex;
            uinfo.Enable = isEnable;
            MessageBox.Show("修改成功");
            BLL.UserManager.updateJobByUid(uinfo);
            parUserInfo.reloadDataTable();
        }

        private void skinButton1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_job_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void comboxsex_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
